import React from 'react';
import { CSSTransition } from 'react-transition-group';

function WrapAnimation(WrappedComponent) {
  return class extends React.PureComponent<any> {
    render() {
      const { match, history } = this.props;
      return (
        <CSSTransition
          in={match !== null}
          classNames={history.action === 'PUSH' ? 'forward' : 'back'}
          timeout={300}
          mountOnEnter
          unmountOnExit
        >
          <WrappedComponent {...this.props} />
        </CSSTransition>
      );
    }
  };
}
export default WrapAnimation;
